package com.easy.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.easy.common.bean.Product;
import com.easy.common.bean.SysMenu;
import com.easy.common.service.IMenuService;
import com.easy.common.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("menu")
public class MenuController {
    @Autowired
    IMenuService menuService;
    @PostMapping("/")
    public ResultData insert(@RequestBody SysMenu menu){
        SysMenu data=menuService.insert(menu);
        return ResultData.success(data);
    }
    @PutMapping("/")
    public ResultData update(@RequestBody SysMenu menu){
        SysMenu data=menuService.update(menu);
        return ResultData.success(data);
    }
    @DeleteMapping("/{id}")
    public ResultData delete(@PathVariable Integer id){
        int result= menuService.delete(id);
        if (result>=1){
            return ResultData.success();
        }else {
            return ResultData.fail();
        }
    }
    @GetMapping("/{id}")
    public ResultData getByID(@PathVariable Integer id){
        SysMenu product=menuService.getByID(id);
        return ResultData.success(product);
    }
    @GetMapping("/page")
    public ResultData getListByPage(Page page, @RequestBody SysMenu menu){
        IPage<SysMenu> data= menuService.getListByPage(page,menu);
        return ResultData.success(data);
    }
    @GetMapping("/list")
    public ResultData getList( SysMenu menu){
        List<SysMenu> data=menuService.getList(menu);
        return ResultData.success(data);
    }


}
